import { getDistrictListByBussiness, getCommunityList, getDistrictList, getworkerList, getCommunityListByDistrict, getOrderStatusList, getBussinessLists, getPackageLists, getNetworkSpeedList, getProvincesList, getNetworkOperatorList, getDictionariesField, getIndexData } from '../services/api';

export default {
  namespace: 'general',
  state: {
    orderStatusList: [],
    packageList: [],
    workerList: [],
    districtList: [],
    communityList: [],
    provincesList: [],
    bussinessLists: [],
    networkSpeedList: [],
    districtByBussinessList: [],
    networkOperatorList: [],
    networkUseStatusList: [],
  },
  effects: {
    *getDistrictList({ payload }, { call, put }) {
      const response = yield call(getDistrictList, payload);
      console.log('getDistrictList', response);
      yield put({
        type: 'districtList',
        payload: response,
      });
    },
    *getworkerList({ payload }, { call, put }) {
      const response = yield call(getworkerList, payload);
      console.log('getworkerList', response);
      yield put({
        type: 'workerList',
        payload: response,
      });
    },
    *getPackageLists({ payload }, { call, put }) {
      const response = yield call(getPackageLists, payload);
      console.log('getPackageLists', response);
      yield put({
        type: 'packageList',
        payload: response,
      });
    },
    *getOrderStatusList({ payload }, { call, put }) {
      const response = yield call(getOrderStatusList, payload);
      yield put({
        type: 'orderStatusList',
        payload: response,
      });
    },
    *getCommunityListByDistrict({ payload }, { call, put }) {
      const response = yield call(getCommunityListByDistrict, payload);
      yield put({
        type: 'communityList',
        payload: response,
      });
    },
    *getCommunityList({ payload }, { call, put }) {
      const response = yield call(getCommunityList, payload);
      yield put({
        type: 'communityList',
        payload: response,
      });
    },
    *getNetworkSpeedList({ payload }, { call, put }) {
      const response = yield call(getNetworkSpeedList, payload);
      console.log('getDistrictList', response);
      yield put({
        type: 'networkSpeedList',
        payload: response,
      });
    },
    *getProvincesList({ payload }, { call, put }) {
      const response = yield call(getProvincesList, payload);
      yield put({
        type: 'provincesList',
        payload: response,
      });
    },
    *getBussinessLists({ payload }, { call, put }) {
      const response = yield call(getBussinessLists, payload);
      yield put({
        type: 'bussinessLists',
        payload: response,
      });
    },
    *getDistrictListByBussiness({ payload }, { call, put }) {
      const response = yield call(getDistrictListByBussiness, payload);
      yield put({
        type: 'districtByBussinessList',
        payload: response,
      });
    },
    *getNetworkOperatorList({ payload }, { call, put }) {
      const response = yield call(getNetworkOperatorList, payload);
      yield put({
        type: 'saveNetworkOperatorList',
        payload: response,
      });
    },
    *getNetworkUseStatus({ payload }, { call, put }) {
      const response = yield call(getDictionariesField, payload);
      yield put({
        type: 'saveNetworkUseStatusList',
        payload: response,
      });
    },
  },
  reducers: {
    districtList(state, action) {
      return {
        ...state,
        districtList: action.payload.data || [],
      };
    },
    workerList(state, action) {
      return {
        ...state,
        workerList: action.payload.data || [],
      };
    },
    packageList(state, action) {
      return {
        ...state,
        packageList: action.payload.data || [],
      };
    },
    orderStatusList(state, action) {
      return {
        ...state,
        orderStatusList: action.payload.data || [],
      };
    },
    communityList(state, action) {
      return {
        ...state,
        communityList: action.payload.data || [],
      };
    },
    networkSpeedList(state, action) {
      return {
        ...state,
        networkSpeedList: action.payload.data || [],
      };
    },
    provincesList(state, action) {
      return {
        ...state,
        provincesList: action.payload.data || [],
      };
    },
    bussinessLists(state, action) {
      return {
        ...state,
        bussinessLists: action.payload.data || [],
      };
    },
    districtByBussinessList(state, action) {
      return {
        ...state,
        districtByBussinessList: action.payload.data || [],
      };
    },
    saveNetworkOperatorList(state, action) {
      return {
        ...state,
        networkOperatorList: action.payload.data || [],
      };
    },
    saveNetworkUseStatusList(state, action) {
      return {
        ...state,
        networkUseStatusList: action.payload.data || [],
      };
    },
  },
};
